package com.example.framework2002a;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.framework2002a.databinding.ActivityHomeBinding;
import com.example.framework2002a.view.activity.FoodActivity;

import java.util.Timer;
import java.util.TimerTask;

public class HomeActivity extends AppCompatActivity {

    private ActivityHomeBinding binding;
    private int time = 6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        binding = DataBindingUtil.setContentView(this,R.layout.activity_home);

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        time--;
                        binding.djs.setText("倒计时:"+time+"");
                        if (time == 0){
                            timer.cancel();
                            //跳转
                            startActivity(new Intent(HomeActivity.this, FoodActivity.class));
                        }
                    }
                });
            }
        },0,1000);
    }
}
